package com.neusoft.exercise;

import javax.imageio.event.IIOReadWarningListener;

/*
 * 算数运算符+ - * / %
 * 赋值运算符= += -+ *= /= %=
 * 关系运算符> < >= <= == != instanceof
 * 逻辑运算符&& || !
 * 按位运算符&|^~
 * 三元运算符 ？：
 * */
public class Operater {

	public static void main(String[] args) {
		
		// 按位运算符 左移 右移 无符号数左移
				int a = -15;// 数据
				int b = 2;// 移位的位数
				System.out.println(a << b);// -60 2的b次乘法
				System.out.println(a >> b);// -4 2的b次除法
				System.out.println(a >>> b);// 1073741820

		// 三元运算符结构可以如下 类似于 if-else if -else
				int iGrade = 98;
				String strGrade = iGrade >= 90 ? "优秀" : 
										iGrade >= 80 ? "良好" : 
											iGrade >= 70 ? "中等" : 
												iGrade >= 60 ? "及格" : "不及格";
												
												
		// 定义变量
		int iValue1 = 4;
		int iValue2 = 5;

		// +运算符
		int iValue3 = iValue1 + iValue2;
		System.out.println("iValue1=" + iValue1);
		System.out.println("iValue2=" + iValue2);
		System.out.println("iValue3= " + iValue3);

		// +=运算符
		iValue3 += iValue1;
		System.out.println("iValue1=" + iValue1);
		System.out.println("iValue3 += iValue1=> " + iValue3);

		// -=运算符
		iValue3 -= iValue1;
		System.out.println("iValue1=" + iValue1);
		System.out.println("iValue3 -= iValue1=> " + iValue3);

		// *=运算符
		iValue3 *= iValue1;
		System.out.println("iValue1=" + iValue1);
		System.out.println("iValue3 *= iValue1=> " + iValue3);

		/// =运算符
		iValue3 /= iValue1;
		System.out.println("iValue1=" + iValue1);
		System.out.println("iValue3 /= iValue1=> " + iValue3);

		// %=运算符
		iValue3 %= iValue1;
		System.out.println("iValue1=" + iValue1);
		System.out.println("iValue3 %= iValue1=> " + iValue3);

		// 先自增
		iValue1 = 4;
		iValue3 = ++iValue1;
		System.out.println("自增++iValue1后iValue1=>" + iValue1);
		System.out.println("iValue3=++iValue1=> " + iValue3);

		// 后自增
		iValue1 = 4;
		iValue3 = iValue1++;
		System.out.println("自增iValue1++后iValue1=>" + iValue1);
		System.out.println("iValue3=iValue1++=> " + iValue3);

		// 先自减
		iValue1 = 4;
		iValue3 = --iValue1;
		System.out.println("自减--iValue1后iValue1=>" + iValue1);
		System.out.println("iValue3=--iValue1=> " + iValue3);

		// 后自减
		iValue1 = 4;
		iValue3 = iValue1--;
		System.out.println("自减iValue1--后iValue1=>" + iValue1);
		System.out.println("iValue3=iValue1--=> " + iValue3);

		// 比较运算符 和条件运算符
		int iValue11 = 6;
		int iValue12 = 6;
		int iValue13 = 0;
		iValue13 = (iValue11 > iValue12) ? 1 : 0;
		System.out.println("iValue13 = (iValue11 < iValue12) ? 1 : 0 =>" + iValue13);
		iValue13 = (iValue11 <= iValue12) ? 1 : 0;
		System.out.println("iValue13 = (iValue11 <= iValue12) ? 1 : 0 =>" + iValue13);
		iValue13 = (iValue11 == iValue12) ? 1 : 0;
		System.out.println("iValue13 = (iValue11 == iValue12) ? 1 : 0 =>" + iValue13);
		iValue13 = (iValue11 != iValue12) ? 1 : 0;
		System.out.println("iValue13 = (iValue11 != iValue12) ? 1 : 0 =>" + iValue13);

		/*
		 * instanceof 它的作用是判断其左边对象是否为其右边类的实例， 返回boolean类型的数据。 可以用来判断继承中的子类的实例是否为父类的实现
		 */
		String str = new String("qeeee");
		boolean bValue1;
		bValue1 = str instanceof String;
		System.out.println("bValue1 = str instanceof String;->" + bValue1);

		bValue1 = str instanceof Object;
		System.out.println("bValue1 = str instanceof String;->" + bValue1);

		// 逻辑运算符 操作数是boolean类型
		int iValue21 = 9;
		int iValue22 = 23;

		// 表达式在&& || 同级只有&&操作符，遇第一个false，编译器优化，逻辑短路，后面部分不计算
		boolean bValue11 = (iValue21 > iValue22) && (++iValue21 < iValue22);
		System.out.println("逻辑段路与&&" + bValue11);
		System.out.println("iValue21 = " + iValue21);
		// 表达式在&& || 同级只有&&操作符，遇第一个false，编译器优化，逻辑短路，后面部分不计算
		boolean bValue12 = (iValue21 < iValue22) || (++iValue21 > iValue22);
		System.out.println("逻辑段路与&&" + bValue12);
		System.out.println("iValue21 = " + iValue21);

		// 位运算符 & | ^ ~
		int iValue100 = -3;// 原码10000011 补码 11111101
		int iValue101 = -4;// 原码10000100 补码 11111100
		int iValue102 = iValue100 & iValue101; // 11111100 -4
		System.out.println("-3 & -4 =" + iValue102);
		iValue102 = iValue100 | iValue101;// 11111101 -3
		System.out.println("-3 | -4 =" + iValue102);
		iValue102 = iValue100 ^ iValue101;// 00000001 1
		System.out.println("-3 ^ -4 =" + iValue102);
		iValue102 = ~iValue100;// 00000010 2
		System.out.println("~(-3)=" + iValue102);

		

	}

}
